﻿<?php 
include 'top1.php';
include '../connect.php';
?>

<div class="ny-right">

  <h3>成绩管理</h3>

     <div id="twjs">
<br><br>



<?php
 if ($_GET['action']=='add'){
    



	$query = mysql_query("insert into kq (course,teacher,student,cj) values 
	
	('{$_POST['course']}','{$_POST['teacher']}','{$_POST['student']}','{$_POST['cj']}')") or die(mysql_error());
		echo "<script type='text/javascript'>alert('添加成功');window.location.href='admin_kq.php';</script>";
}
if ($_GET['action']=="del"){
	$query = mysql_query("delete from kq where id= ".$_GET['id']);
	echo "<script type='text/javascript'>alert('删除成功');window.location.href='admin_kq.php';</script>";
}


?>



<table border=1px cellpadding="0" cellspacing="0" width="670" style="margin:0 auto;">   
<?php 	
echo '<tr><td>课程名</td><td>教师名</td>  <td>学生名</td> <td>考试分数</td> <td>修改</td> <td>删除</td></tr>';  
if ($_GET[page]==""){
$_GET[page]=1;}
if (is_numeric($_GET[page])){
$page_size=5;     							
$query="select count(*) as total from kq  order by cj desc";   
$result=mysql_query($query);      					//查询符合条件的记录总条数
$message_count=mysql_result($result,0,"total");		//要显示的总记录数
$page_count=ceil($message_count/$page_size);	  	//根据记录总数除以每页显示的记录数求出所分的页数
$offset=($_GET[page]-1)*$page_size;						//计算下一页从第几条数据开始循环  
$sql=mysql_query("select * from kq  order by cj desc limit $offset, $page_size");
$row=mysql_fetch_object($sql);
if(!$row){
echo "<font color='red'>暂无新闻信息!</font>";
}
do{
?>
   
 <tr><td><?php echo $row->course;?> </td><td><?php echo $row->teacher;?> </td><td><?php echo $row->student;?> </td> <td><?php echo $row->cj;?> </td><td><a href="kq_xiu.php?id=<?php echo $row->id;?>">修改</a></td><td><a href="?action=del&id=<?php echo $row->id;?>">删除</a> </td></tr>
            
<?php
}
while($row=mysql_fetch_object($sql));
}
?>	
	     <br>  <br>
                        <tr>
                        <td align="center" colspan="7">
                          <!--  翻页条 -->
							页次：<?php echo $_GET[page];?>/<?php echo $page_count;?>页&nbsp;记录：<?php echo $message_count;?> 条&nbsp; 
							
							<?php
							/*  如果当前页不是首页  */
							if($_GET[page]!=1){
							/*  显示“首页”超链接  */
							echo  "<a href=?page=1>首页</a>&nbsp;";
							/*  显示“上一页”超链接  */
							echo "<a href=?page=".($_GET[page]-1).">上一页</a>&nbsp;";
							}
							/*  如果当前页不是尾页  */
							if($_GET[page]<$page_count){
							/*  显示“下一页”超链接  */
							echo "<a href=?page=".($_GET[page]+1).">下一页</a>&nbsp;";
							/*  显示“尾页”超链接  */
							echo  "<a href=?page=".$page_count.">尾页</a>";
							}
							
							
							mysql_free_result($sql);
							mysql_close($conn);
							?>		
   

</table>
<?php
	$query3 = mysql_query("select avg(cql) as pjf from kq");
    $row3 = mysql_fetch_array($query3,MYSQL_ASSOC)



?>
<br>





 <style  type="text/css">
 table td { padding-left:5px; }
  table td p { width:400px;word-break:break-all ;}
 
 </style>
 
 <br> <br> <br> <br>


<form id="form1" name="form1" method="post" action="?action=add" style=" padding:0 0 0 100px;">
          <table width="600" border="1" align="center">
            
            
             <tr>
              <td align="right">课程名:</td>
              <td>     <select name="course"> <?php
        $query = mysql_query("select * from course ");
				
	    while($row = mysql_fetch_array($query,MYSQL_ASSOC)){
			
						echo '<option value="'.$row['course'].'">'.$row['course'].'</option>';
				}
				
      ?>
      </select>
 </td>
            </tr>
              <tr>
              <td align="right">任课教师:</td>
              <td> <?php
        $query = mysql_query("select * from teacher ");
				
	    while($row = mysql_fetch_array($query,MYSQL_ASSOC)){
			
                        echo '<input name="teacher" type="radio" value="'.$row['tname'].'" />'.$row['tname'].' ';
				}
				
      ?>      </td>
            </tr>
            
           
            <tr>
              <td align="right">学生名:</td>
              <td><input name="student" type="text" /></td>
            </tr>
            <tr>
              <td align="right">考试成绩:</td>
              <td><input name="cj" type="text" /></td>
            </tr>
           <tr>
              <td colspan="2" align="center"><input type="submit" name="submit" value="添加" /></td>
            </tr>
          </table>
          <p align="center">&nbsp;</p>
		
        </form>
</div>
</div>

<div class="clear"></div>
</div>


<?php 
include 'foot.php';

?>
